package com.fenghongzhang.test.zxing;

import android.Manifest;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.fenghongzhang.test.R;
import com.uuzuche.lib_zxing.activity.CaptureActivity;
import com.uuzuche.lib_zxing.activity.CodeUtils;

public class Main7Activity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main7);

        String[] permissions=new String[]{Manifest.permission.
                WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA};
            requestPermissions(permissions,200);

    }

    public void btn(View view) {
        Intent intent = new Intent(Main7Activity.this, CaptureActivity.class);
        startActivityForResult(intent, 100);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (data != null) {
            Bundle bundle = data.getExtras();
            if (bundle != null) {
                int type = bundle.getInt(CodeUtils.RESULT_TYPE);
                if (type == CodeUtils.RESULT_SUCCESS) {
                    String str = bundle.getString(CodeUtils.RESULT_STRING);
                    Toast.makeText(this, str, Toast.LENGTH_SHORT).show();
                }
            }
        }
    }

    public void btn1(View view) {
        String str = "wangxianbing";
        ImageView imageView = findViewById(R.id.img);
//        Bitmap mBitmap = CodeUtils.createImage(str, 400, 400, null);
        Bitmap mBitmap = CodeUtils.createImage(str, 400, 400, BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher));
        imageView.setImageBitmap(mBitmap);
    }
}
